package org.itzixi.config;


import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.itzixi.adapter.AliyunStorageAdapter;
import org.itzixi.adapter.MinioStorageAdapter;
import org.itzixi.adapter.StorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.Map;

@Configuration
@RefreshScope
@Slf4j
public class StorageConfig {

    @Value("${storage.service.type}")
    private String storageType;



    @Resource
    private Map<String, StorageAdapter> adapterMap;


    @Bean
    @Primary
    @RefreshScope
    public StorageAdapter storageService() {
        log.info("当前适配器为storageType:{}", storageType);
        StorageAdapter storageAdapter = adapterMap.get(storageType);
        if (storageType != null){
            log.info("storageType:{}", storageType);
            return storageAdapter;
        }  else {
            throw new IllegalArgumentException("未配置存储服务类型");
        }

    }



}
